/*
 * 企业列表
 * @Author: along
 * @Date: 2019-12-13 09:30:00
 */
<template>
    <div class="container workService">
        <!-- header -->
        <div class="headerMain">
            <div class="header-box">
                <p class="header-box-title">姓名</p>
                <el-input
                    v-model="user_name"
                    placeholder="请输入姓名"
                    suffix-icon="el-icon-search"
                    size="small"
                    clearable
                    class="search-ipt"
                    @change="getTableData(1)"
                    @keyup.native.enter="getTableData(1)"
                />
            </div>
            <div class="header-box">
                <p class="header-box-title">用户</p>
                <el-input
                    v-model="true_name"
                    placeholder="用户ID或手机号"
                    suffix-icon="el-icon-search"
                    size="small"
                    clearable
                    class="search-ipt"
                    @change="getTableData(1)"
                    @keyup.native.enter="getTableData(1)"
                />
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="companyList"
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="true_name"
                label="用户姓名"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="student_no"
                label="用户ID"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="160"
            />
            <el-table-column
                prop="phone"
                label="电话号码"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                prop="school_name"
                label="学校信息"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    <span>{{ scope.row.school_name }} - {{ scope.row.college_name }}</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="hire_num"
                label="绑定公司"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    <span
                        class="cursor-font"
                        @click="fnGoHire(scope.row)"
                    >{{ scope.row.hire_num }}</span>
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
            >
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        class="curse-add"
                        @click="fnUnnindhire(scope.row)"
                    >
                        解绑公司
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- 解绑公司 -->
        <el-dialog
            title="解绑公司"
            :visible.sync="dialogVisibleUnBind"
            width="580px"
            :close-on-click-modal="false"
            class="dialogVisibleUnBind"
            center
        >
            <el-checkbox-group v-model="checkListKf">
                <div
                    v-for="(item,index) in kfList"
                    :key="index"
                >
                    <el-checkbox
                        :label="item.hire_no"
                        class="el-checkList"
                    >
                        <span>{{ item.hire_no }} - {{ item.company_name }} - {{ item.username }}</span>
                    </el-checkbox>
                </div>
            </el-checkbox-group>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    size="small"
                    @click="dialogVisibleUnBind = false">取 消</el-button>
                <el-button
                    type="primary"
                    size="small"
                    :disabled="ifBind"
                    @click="fnUntying()">解 绑</el-button>
            </span>
        </el-dialog>
        <!-- /解绑公司 -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>
    </div>
</template>

<script>
export default {
    /**
     * @param  {Object}    authResult                           //表单权限
     * @param  {Array}     tableData                            //表单数据
     * @param  {Object}    page                                 //表单分页
     * @param  {String}    true_name                            //名称搜索字段
     * @param  {boolean}   dialogVisibleUnBind                  //弹窗开关
     * @param  {Array}     checkListKf                          //解绑客服
     * @param  {Array}     kfList                               //绑定客服数据
     * @param  {Boolean}   ifBind                               //是否选中数据
     * @param  {String}    student_no                           //用户编号
     */
    data () {
        return {
            hire_no: '',
            student_no: '',
            ifBind: true,
            kfList: [],
            checkListKf: [],
            dialogVisibleUnBind: false,
            user_name: '',
            true_name: '',
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {}
        };
    },
    filters: {},
    computed: {},
    watch: {
        checkListKf (val) {
            if (val.length == 0) {
                this.ifBind = true;
            } else {
                this.ifBind = false;
            }
        },
        dialogVisibleUnBind (val) {
            if (!val) {
                this.checkListKf = [];
            }
        }
    },
    mounted () {
        this.authResult = this.$route.meta.authResult;
        this.fnParamUrl();
        this.fnBreadcrumb();
        this.getTableData();
    },
    methods: {
        /**
         * 设置表单header
         */
        fnBreadcrumb () {
            this.$store.commit('SET_HEADER', [{ title: "APP后台"},{title: '工作'},{title: "工作客服"}]);
        },

        /**
         * 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/hire_kf%5Cget_list', {
                page_id: page || this.page.now_page,
                keyword: this.user_name,
                keyword_student_id: this.true_name,
                hire_no: this.hire_no
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * 跳转企业列表
         */
        fnGoHire (row) {
            this.$router.replace({
                name: 'companyList',
                query: {
                    student_no: row.student_no
                }
            });
        },

        /**
         * 获取路由参数
         */
        fnParamUrl () {
            let query = this.$route.query;

            if (query.hire_no !== undefined) {
                this.hire_no = query.hire_no;
            }
        },

        /**
         * 解绑客服
         */
        fnUnnindhire (row) {
            //获取编号
            this.kfList = [];
            this.student_no = row.student_no;
            this.dialogVisibleUnBind = !this.dialogVisibleUnBind;
            this.$post('/student/hire_kf%5Cget_bind_hire_list',{
                student_no: row.student_no
            },resp=> {
                if (resp.code == 1) {
                    if (resp.data.length !== 0) {
                        this.kfList = this.kfList.concat(resp.data.list);
                    }
                }
            });
        },

        /**
         * 确认解绑
         */
        fnUntying () {
            this.$post('/student/hire_kf%5Cun_bind_hire',{
                student_no: this.student_no,
                hire_nos: this.checkListKf.join()
            },resp=> {
                if (resp.code == 1) {
                    this.getTableData();
                    this.dialogVisibleUnBind = !this.dialogVisibleUnBind;
                    this.$message({
                        type: 'success',
                        message: '解绑成功',
                        center: true
                    });
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'waring',
                        message: resp.msg,
                        center: true
                    });
                }
            });
        },

        /**
         * 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 5px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .headerMain {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            .header-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
</style>
<style lang="less">
    .workService .el-table__body-wrapper .el-table__body .el-table__row td {
        border-right: none;
    }
    .workService .el-table__header-wrapper .el-table__header .has-gutter tr th {
        border-right: none;
    }
    .workService .el-table .el-table_1_column_6  .cell {
        position: relative;
    }
    .workService .el-range-editor--small .el-range-separator{
        padding: 0 1px !important;
    }
</style>